package com.hskn.hss.module.tlrepaircfg.vo;

import com.hskn.hss.core.annotation.Excel;
import com.hskn.hss.module.depart.entity.SysDepart;
import com.hskn.hss.module.tlcar.entity.TlCar;
import com.hskn.hss.module.tlcartype.entity.TlCarType;
import com.hskn.hss.module.tlrepaircfg.entity.TlRepairCfg;
import com.hskn.hss.module.user.entity.User;
import com.hskn.hss.utils.Tools;
import lombok.Data;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * <p>
 *
 * </p>
 *
 * @author hskn
 * @since 2021-05-05
 */
@Data
public class TlRepairCfgExecelVO implements Serializable {
    /**
     * 车辆id
     */
    private String carnumid;
    /**
     * 车牌号
     */
    @Excel(name = "车牌号", align = Excel.Align.CENTER, height = 18, width = 16)
    private String carCardNum;
    /**
     * 车辆类型
     */
    @Excel(name = "车辆类型", align = Excel.Align.CENTER, height = 18, width = 16)
    private String carTypeName;
    /**
     * 驾驶员
     */
    @Excel(name = "驾驶员", align = Excel.Align.CENTER, height = 18, width = 16)
    private String driverName;
    /**
     * 创建部门id
     */
    private String deptid;
    /**
     * 机构名称
     */
    @Excel(name = "所属机构", align = Excel.Align.CENTER, height = 18, width = 24)
    private String deptName;
    /**
     * 码表里程(km)
     */
    @Excel(name = "码表里程", align = Excel.Align.CENTER, height = 18, width = 16, color = IndexedColors.GREEN, cellType = Excel.ColumnType.NUMERIC)
    private BigDecimal clockmileage;
    /**
     * 总费用(元)
     */
    @Excel(name = "总费用", align = Excel.Align.CENTER, height = 18, width = 16, color = IndexedColors.DARK_YELLOW, cellType = Excel.ColumnType.NUMERIC)
    private BigDecimal totalcost;
    /**
     * 维修部位
     */
    private String repairreason;
    /**
     * 维修部位
     */
    @Excel(name = "维修部位", align = Excel.Align.CENTER, height = 18, width = 16)
    private String repairreasonName;
    /**
     * 维修时间
     */
    private Date costtime;
    /**
     * 维修时间
     */
    @Excel(name = "维修时间", align = Excel.Align.CENTER, height = 18, width = 16)
    private String costtimeString;
    /**
     * 地址
     */
    @Excel(name = "地址", align = Excel.Align.CENTER, height = 18, width = 36)
    private String address;
    /**
     * 缴费人
     */
    @Excel(name = "缴费人", align = Excel.Align.CENTER, height = 18, width = 16)
    private String payusername;
    /**
     * 维修单号
     */
    @Excel(name = "维修单号", align = Excel.Align.CENTER, height = 18, width = 24)
    private String orderno;


    public TlRepairCfgExecelVO() {
    }

    public TlRepairCfgExecelVO(String carnumid, String carCardNum, String carTypeName, String driverName, String deptid, String deptName, BigDecimal clockmileage, BigDecimal totalcost, String repairreason, String repairreasonName, Date costtime, String costtimeString, String address, String payusername, String orderno) {
        this.carnumid = carnumid;
        this.carCardNum = carCardNum;
        this.carTypeName = carTypeName;
        this.driverName = driverName;
        this.deptid = deptid;
        this.deptName = deptName;
        this.clockmileage = clockmileage;
        this.totalcost = totalcost;
        this.repairreason = repairreason;
        this.repairreasonName = repairreasonName;
        this.costtime = costtime;
        this.costtimeString = costtimeString;
        this.address = address;
        this.payusername = payusername;
        this.orderno = orderno;
    }

    public static TlRepairCfgExecelVO buildTlRepairCfgExecelVO(TlRepairCfg repairCfg, TlCar car, TlCarType carType, User user, SysDepart depart) {
        /**
         * 车辆id
         */
        String carnumid = repairCfg.getCarnumid();
        /**
         * 车牌号
         */
        String carCardNum = car.getCarnumber();
        /**
         * 车辆类型
         */
        String carTypeName = carType.getTypename();
        /**
         * 驾驶员
         */
        String driverName = user.getName();
        /**
         * 创建部门id
         */
        String deptid = repairCfg.getDeptid();
        /**
         * 机构名称
         */
        String deptName = depart.getDepartName();
        /**
         * 码表里程(km)
         */
        BigDecimal clockmileage = Objects.nonNull(repairCfg.getClockmileage())?new BigDecimal(repairCfg.getClockmileage()).setScale(2,BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO;

        /**
         * 总费用(元)
         */
        BigDecimal totalcost = Objects.nonNull(repairCfg.getTotalcost())?repairCfg.getTotalcost().setScale(2,BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO;

        /**
         * 维修部位
         */
        String repairreason = repairCfg.getRepairreason();
        /**
         * 维修部位
         */
        String repairreasonName = repairCfg.getRepairreasonName();
        /**
         * 维修时间
         */
        Date costtime = repairCfg.getCosttime();
        /**
         * 维修时间
         */
        String costtimeString = Tools.getYearMonthDayString(repairCfg.getCosttime());

        /**
         * 地址
         */
        String address = repairCfg.getPlace();
        /**
         * 缴费人
         */
        String payusername = repairCfg.getPayusername();
        /**
         * 维修单号
         */
        String orderno = repairCfg.getOrderno();

        return new TlRepairCfgExecelVO(carnumid,carCardNum,carTypeName,driverName,deptid,deptName,clockmileage,totalcost,repairreason,repairreasonName
        ,costtime,costtimeString,address,payusername,orderno);
    }

}
